screen: Implement old monitor apis generically
Implement all the monitor-related GdkScreen apis based on GdkMonitor.
This commit is contained in:
196
gdk/gdkscreen.c
196
gdk/gdkscreen.c
@ -194,52 +194,20 @@ _gdk_screen_close (GdkScreen *screen)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fallback used when the monitor "at" a point or window
|
static int
|
||||||
* doesn’t exist.
|
get_monitor_num (GdkMonitor *monitor)
|
||||||
*/
|
|
||||||
static gint
|
|
||||||
get_nearest_monitor (GdkScreen *screen,
|
|
||||||
gint x,
|
|
||||||
gint y)
|
|
||||||
{
|
{
|
||||||
gint num_monitors, i;
|
GdkDisplay *display;
|
||||||
gint nearest_dist = G_MAXINT;
|
int n_monitors, i;
|
||||||
gint nearest_monitor = 0;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
display = gdk_monitor_get_display (monitor);
|
||||||
|
n_monitors = gdk_display_get_n_monitors (display);
|
||||||
num_monitors = gdk_screen_get_n_monitors (screen);
|
for (i = 0; i < n_monitors; i++)
|
||||||
|
|
||||||
for (i = 0; i < num_monitors; i++)
|
|
||||||
{
|
{
|
||||||
GdkRectangle monitor;
|
if (gdk_display_get_monitor (display, i) == monitor)
|
||||||
gint dist_x, dist_y, dist;
|
return i;
|
||||||
|
|
||||||
gdk_screen_get_monitor_geometry (screen, i, &monitor);
|
|
||||||
|
|
||||||
if (x < monitor.x)
|
|
||||||
dist_x = monitor.x - x;
|
|
||||||
else if (x >= monitor.x + monitor.width)
|
|
||||||
dist_x = x - (monitor.x + monitor.width) + 1;
|
|
||||||
else
|
|
||||||
dist_x = 0;
|
|
||||||
|
|
||||||
if (y < monitor.y)
|
|
||||||
dist_y = monitor.y - y;
|
|
||||||
else if (y >= monitor.y + monitor.height)
|
|
||||||
dist_y = y - (monitor.y + monitor.height) + 1;
|
|
||||||
else
|
|
||||||
dist_y = 0;
|
|
||||||
|
|
||||||
dist = dist_x + dist_y;
|
|
||||||
if (dist < nearest_dist)
|
|
||||||
{
|
|
||||||
nearest_dist = dist;
|
|
||||||
nearest_monitor = i;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
return nearest_monitor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -260,26 +228,14 @@ gdk_screen_get_monitor_at_point (GdkScreen *screen,
|
|||||||
gint x,
|
gint x,
|
||||||
gint y)
|
gint y)
|
||||||
{
|
{
|
||||||
gint num_monitors, i;
|
GdkDisplay *display;
|
||||||
|
GdkMonitor *monitor;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
||||||
|
|
||||||
num_monitors = gdk_screen_get_n_monitors (screen);
|
display = gdk_screen_get_display (screen);
|
||||||
|
monitor = gdk_display_get_monitor_at_point (display, x, y);
|
||||||
for (i=0;i<num_monitors;i++)
|
return get_monitor_num (monitor);
|
||||||
{
|
|
||||||
GdkRectangle monitor;
|
|
||||||
|
|
||||||
gdk_screen_get_monitor_geometry (screen, i, &monitor);
|
|
||||||
|
|
||||||
if (x >= monitor.x &&
|
|
||||||
x < monitor.x + monitor.width &&
|
|
||||||
y >= monitor.y &&
|
|
||||||
y < (monitor.y + monitor.height))
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
return get_nearest_monitor (screen, x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -297,38 +253,18 @@ gdk_screen_get_monitor_at_point (GdkScreen *screen,
|
|||||||
* Since: 2.2
|
* Since: 2.2
|
||||||
**/
|
**/
|
||||||
gint
|
gint
|
||||||
gdk_screen_get_monitor_at_window (GdkScreen *screen,
|
gdk_screen_get_monitor_at_window (GdkScreen *screen,
|
||||||
GdkWindow *window)
|
GdkWindow *window)
|
||||||
{
|
{
|
||||||
gint num_monitors, i, area = 0, screen_num = -1;
|
GdkDisplay *display;
|
||||||
GdkRectangle win_rect;
|
GdkMonitor *monitor;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
||||||
|
g_return_val_if_fail (GDK_IS_WINDOW (window), -1);
|
||||||
|
|
||||||
gdk_window_get_geometry (window, &win_rect.x, &win_rect.y, &win_rect.width,
|
display = gdk_screen_get_display (screen);
|
||||||
&win_rect.height);
|
monitor = gdk_display_get_monitor_at_window (display, window);
|
||||||
gdk_window_get_origin (window, &win_rect.x, &win_rect.y);
|
return get_monitor_num (monitor);
|
||||||
num_monitors = gdk_screen_get_n_monitors (screen);
|
|
||||||
|
|
||||||
for (i=0;i<num_monitors;i++)
|
|
||||||
{
|
|
||||||
GdkRectangle tmp_monitor, intersect;
|
|
||||||
|
|
||||||
gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
|
|
||||||
gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
|
|
||||||
|
|
||||||
if (intersect.width * intersect.height > area)
|
|
||||||
{
|
|
||||||
area = intersect.width * intersect.height;
|
|
||||||
screen_num = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (screen_num >= 0)
|
|
||||||
return screen_num;
|
|
||||||
else
|
|
||||||
return get_nearest_monitor (screen,
|
|
||||||
win_rect.x + win_rect.width / 2,
|
|
||||||
win_rect.y + win_rect.height / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -703,6 +639,16 @@ gdk_screen_get_root_window (GdkScreen *screen)
|
|||||||
return GDK_SCREEN_GET_CLASS (screen)->get_root_window (screen);
|
return GDK_SCREEN_GET_CLASS (screen)->get_root_window (screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GdkMonitor *
|
||||||
|
get_monitor (GdkScreen *screen,
|
||||||
|
gint n)
|
||||||
|
{
|
||||||
|
GdkDisplay *display;
|
||||||
|
|
||||||
|
display = gdk_screen_get_display (screen);
|
||||||
|
return gdk_display_get_monitor (display, n);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdk_screen_get_n_monitors:
|
* gdk_screen_get_n_monitors:
|
||||||
* @screen: a #GdkScreen
|
* @screen: a #GdkScreen
|
||||||
@ -716,9 +662,12 @@ gdk_screen_get_root_window (GdkScreen *screen)
|
|||||||
gint
|
gint
|
||||||
gdk_screen_get_n_monitors (GdkScreen *screen)
|
gdk_screen_get_n_monitors (GdkScreen *screen)
|
||||||
{
|
{
|
||||||
|
GdkDisplay *display;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
||||||
|
|
||||||
return GDK_SCREEN_GET_CLASS (screen)->get_n_monitors (screen);
|
display = gdk_screen_get_display (screen);
|
||||||
|
return gdk_display_get_n_monitors (display);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -741,9 +690,17 @@ gdk_screen_get_n_monitors (GdkScreen *screen)
|
|||||||
gint
|
gint
|
||||||
gdk_screen_get_primary_monitor (GdkScreen *screen)
|
gdk_screen_get_primary_monitor (GdkScreen *screen)
|
||||||
{
|
{
|
||||||
|
GdkDisplay *display;
|
||||||
|
GdkMonitor *primary;
|
||||||
|
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
||||||
|
|
||||||
return GDK_SCREEN_GET_CLASS (screen)->get_primary_monitor (screen);
|
display = gdk_screen_get_display (screen);
|
||||||
|
primary = gdk_display_get_primary_monitor (display);
|
||||||
|
if (primary)
|
||||||
|
return get_monitor_num (primary);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -761,11 +718,15 @@ gint
|
|||||||
gdk_screen_get_monitor_width_mm (GdkScreen *screen,
|
gdk_screen_get_monitor_width_mm (GdkScreen *screen,
|
||||||
gint monitor_num)
|
gint monitor_num)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
GdkMonitor *monitor;
|
||||||
g_return_val_if_fail (monitor_num >= 0, -1);
|
|
||||||
g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), -1);
|
|
||||||
|
|
||||||
return GDK_SCREEN_GET_CLASS (screen)->get_monitor_width_mm (screen, monitor_num);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
||||||
|
|
||||||
|
monitor = get_monitor (screen, monitor_num);
|
||||||
|
|
||||||
|
g_return_val_if_fail (monitor != NULL, -1);
|
||||||
|
|
||||||
|
return gdk_monitor_get_width_mm (monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -783,11 +744,15 @@ gint
|
|||||||
gdk_screen_get_monitor_height_mm (GdkScreen *screen,
|
gdk_screen_get_monitor_height_mm (GdkScreen *screen,
|
||||||
gint monitor_num)
|
gint monitor_num)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
GdkMonitor *monitor;
|
||||||
g_return_val_if_fail (monitor_num >= 0, -1);
|
|
||||||
g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), -1);
|
|
||||||
|
|
||||||
return GDK_SCREEN_GET_CLASS (screen)->get_monitor_height_mm (screen, monitor_num);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
|
||||||
|
|
||||||
|
monitor = get_monitor (screen, monitor_num);
|
||||||
|
|
||||||
|
g_return_val_if_fail (monitor != NULL, -1);
|
||||||
|
|
||||||
|
return gdk_monitor_get_height_mm (monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -808,11 +773,15 @@ gchar *
|
|||||||
gdk_screen_get_monitor_plug_name (GdkScreen *screen,
|
gdk_screen_get_monitor_plug_name (GdkScreen *screen,
|
||||||
gint monitor_num)
|
gint monitor_num)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
GdkMonitor *monitor;
|
||||||
g_return_val_if_fail (monitor_num >= 0, NULL);
|
|
||||||
g_return_val_if_fail (monitor_num < gdk_screen_get_n_monitors (screen), NULL);
|
|
||||||
|
|
||||||
return GDK_SCREEN_GET_CLASS (screen)->get_monitor_plug_name (screen, monitor_num);
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
||||||
|
|
||||||
|
monitor = get_monitor (screen, monitor_num);
|
||||||
|
|
||||||
|
g_return_val_if_fail (monitor != NULL, NULL);
|
||||||
|
|
||||||
|
return g_strdup (gdk_monitor_get_model (monitor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -840,11 +809,15 @@ gdk_screen_get_monitor_geometry (GdkScreen *screen,
|
|||||||
gint monitor_num,
|
gint monitor_num,
|
||||||
GdkRectangle *dest)
|
GdkRectangle *dest)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GDK_IS_SCREEN (screen));
|
GdkMonitor *monitor;
|
||||||
g_return_if_fail (monitor_num >= 0);
|
|
||||||
g_return_if_fail (monitor_num < gdk_screen_get_n_monitors (screen));
|
|
||||||
|
|
||||||
GDK_SCREEN_GET_CLASS(screen)->get_monitor_geometry (screen, monitor_num, dest);
|
g_return_if_fail (GDK_IS_SCREEN (screen));
|
||||||
|
|
||||||
|
monitor = get_monitor (screen, monitor_num);
|
||||||
|
|
||||||
|
g_return_if_fail (monitor != NULL);
|
||||||
|
|
||||||
|
gdk_monitor_get_geometry (monitor, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -877,11 +850,16 @@ gdk_screen_get_monitor_workarea (GdkScreen *screen,
|
|||||||
gint monitor_num,
|
gint monitor_num,
|
||||||
GdkRectangle *dest)
|
GdkRectangle *dest)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GDK_IS_SCREEN (screen));
|
GdkMonitor *monitor;
|
||||||
g_return_if_fail (monitor_num >= 0);
|
|
||||||
g_return_if_fail (monitor_num < gdk_screen_get_n_monitors (screen));
|
|
||||||
|
|
||||||
GDK_SCREEN_GET_CLASS (screen)->get_monitor_workarea (screen, monitor_num, dest);
|
g_return_if_fail (GDK_IS_SCREEN (screen));
|
||||||
|
|
||||||
|
monitor = get_monitor (screen, monitor_num);
|
||||||
|
|
||||||
|
g_return_if_fail (monitor != NULL);
|
||||||
|
|
||||||
|
/* FIXME */
|
||||||
|
gdk_monitor_get_geometry (monitor, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user