Esempio n. 1
0
/* The panel can't use gdk_screen_get_monitor_at_point() since it has its own
 * view of which monitors are present. Look at get_monitors_for_screen() above
 * to see why. */
int
panel_multiscreen_get_monitor_at_point (int x,
                                        int y)
{
	int i;
	GdkRectangle *geoms;
	int min_dist_squared;
	int closest_monitor;

	geoms = geometries[0];

	min_dist_squared = G_MAXINT32;
	closest_monitor = 0;

	for (i = 0; i < monitors; i++) {
		int dist_x, dist_y;
		int dist_squared;

		dist_x = axis_distance (x, geoms[i].x, geoms[i].width);
		dist_y = axis_distance (y, geoms[i].y, geoms[i].height);

		if (dist_x == 0 && dist_y == 0)
			return i;

		dist_squared = dist_x * dist_x + dist_y * dist_y;

		if (dist_squared < min_dist_squared) {
			min_dist_squared = dist_squared;
			closest_monitor = i;
		}
	}

	return closest_monitor;
}
Esempio n. 2
0
/* The panel can't use gdk_screen_get_monitor_at_point() since it has its own
 * view of which monitors are present. Look at get_monitors_for_screen() above
 * to see why. */
int
panel_multiscreen_get_monitor_at_point (GdkScreen *screen,
					int        x,
					int        y)
{
	int n_screen;
	int i;
	int n_monitors;
	GdkRectangle *geoms;
	int min_dist_squared;
	int closest_monitor;

	/* not -1 as callers expect a real monitor */
	g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);

	n_screen = gdk_screen_get_number (screen);

	n_monitors = monitors[n_screen];
	geoms = geometries[n_screen];

	min_dist_squared = G_MAXINT32;
	closest_monitor = 0;

	for (i = 0; i < n_monitors; i++) {
		int dist_x, dist_y;
		int dist_squared;

		dist_x = axis_distance (x, geoms[i].x, geoms[i].width);
		dist_y = axis_distance (y, geoms[i].y, geoms[i].height);

		if (dist_x == 0 && dist_y == 0)
			return i;

		dist_squared = dist_x * dist_x + dist_y * dist_y;

		if (dist_squared < min_dist_squared) {
			min_dist_squared = dist_squared;
			closest_monitor = i;
		}
	}

	return closest_monitor;
}