]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkscreen.c
Translation updated by Ivar Smolin.
[~andy/gtk] / gdk / gdkscreen.c
index c28855e2c2476b4b12f8f8567acbff7a5a983fc9..8e08e5363bf8027c4d26d5621d39f1f18790b9bf 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
 #include "gdk.h"               /* For gdk_rectangle_intersect() */
 #include "gdkcolor.h"
-#include "gdkinternals.h"
 #include "gdkwindow.h"
 #include "gdkscreen.h"
+#include "gdkalias.h"
+
+static void gdk_screen_class_init  (GdkScreenClass *klass);
+static void gdk_screen_dispose     (GObject        *object);
+
+enum
+{
+  SIZE_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+static gpointer parent_class = NULL;
 
 GType
 gdk_screen_get_type (void)
@@ -39,7 +53,7 @@ gdk_screen_get_type (void)
          sizeof (GdkScreenClass),
          (GBaseInitFunc) NULL,
          (GBaseFinalizeFunc) NULL,
-         NULL,                 /* class_init */
+         (GClassInitFunc) gdk_screen_class_init,
          NULL,                 /* class_finalize */
          NULL,                 /* class_data */
          sizeof (GdkScreen),
@@ -54,32 +68,124 @@ gdk_screen_get_type (void)
   return object_type;
 }
 
+static void
+gdk_screen_class_init (GdkScreenClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  parent_class = g_type_class_peek_parent (klass);
+  
+  object_class->dispose = gdk_screen_dispose;
+  
+  /**
+   * GdkScreen::size-changed:
+   * @screen: the object on which the signal is emitted
+   * 
+   * The ::size_changed signal is emitted when the pixel width or 
+   * height of a screen changes.
+   *
+   * Since: 2.2
+   */
+  signals[SIZE_CHANGED] =
+    g_signal_new ("size_changed",
+                  G_OBJECT_CLASS_TYPE (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (GdkScreenClass, size_changed),
+                  NULL, NULL,
+                  g_cclosure_marshal_VOID__VOID,
+                  G_TYPE_NONE,
+                  0);
+}
+
+static void
+gdk_screen_dispose (GObject *object)
+{
+  GdkScreen *screen = GDK_SCREEN (object);
+  gint i;
+
+  for (i = 0; i < 32; ++i)
+    {
+      if (screen->exposure_gcs[i])
+       g_object_unref (screen->exposure_gcs[i]);
+
+      if (screen->normal_gcs[i])
+       g_object_unref (screen->normal_gcs[i]);
+    }
+
+  G_OBJECT_CLASS (parent_class)->dispose (object);
+}
 
-/**
- * gdk_screen_close:
- * @screen: a #GdkScreen
- *
- * Closes the @screen connection and cleanup its resources.
- * Note that this function is called automatically by gdk_display_close().
- **/
 void 
-gdk_screen_close (GdkScreen *screen)
+_gdk_screen_close (GdkScreen *screen)
 {
   g_return_if_fail (GDK_IS_SCREEN (screen));
+
+  if (!screen->closed)
+    {
+      screen->closed = TRUE;
+      g_object_run_dispose (G_OBJECT (screen));
+    }
+}
+
+/* Fallback used when the monitor "at" a point or window
+ * doesn't exist.
+ */
+static gint
+get_nearest_monitor (GdkScreen *screen,
+                    gint       x,
+                    gint       y)
+{
+  gint num_monitors, i;
+  gint nearest_dist = G_MAXINT;
+  gint nearest_monitor = 0;
   
-  g_object_run_dispose (G_OBJECT (screen));
+  g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
+
+  num_monitors = gdk_screen_get_n_monitors (screen);
+  
+  for (i = 0; i < num_monitors; i++)
+    {
+      GdkRectangle monitor;
+      gint dist_x, dist_y;
+      
+      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;
+
+      if (MIN (dist_x, dist_y) < nearest_dist)
+       {
+         nearest_dist = MIN (dist_x, dist_y);
+         nearest_monitor = i;
+       }
+    }
+
+  return nearest_monitor;
 }
 
 /**
  * gdk_screen_get_monitor_at_point:
- * @screen : a #GdkScreen.
- * @x : the x coordinate in the virtual screen.
- * @y : the y coordinate in the virtual screen.
+ * @screen: a #GdkScreen.
+ * @x: the x coordinate in the virtual screen.
+ * @y: the y coordinate in the virtual screen.
  *
  * Returns the monitor number in which the point (@x,@y) is located.
  *
- * Returns: the monitor number in which the point (@x,@y) belong, or
- *   -1 if the point is not in any monitor.
+ * Returns: the monitor number in which the point (@x,@y) lies, or
+ *   a monitor close to (@x,@y) if the point is not in any monitor.
+ *
+ * Since: 2.2
  **/
 gint 
 gdk_screen_get_monitor_at_point (GdkScreen *screen,
@@ -105,23 +211,27 @@ gdk_screen_get_monitor_at_point (GdkScreen *screen,
         return i;
     }
 
-  return -1;
+  return get_nearest_monitor (screen, x, y);
 }
 
 /**
  * gdk_screen_get_monitor_at_window:
  * @screen: a #GdkScreen.
  * @window: a #GdkWindow
- * @returns: the monitor number in which most of @window is located.
+ * @returns: the monitor number in which most of @window is located,
+ *           or if @window does not intersect any monitors, a monitor,
+ *           close to @window.
+ *
+ * Returns the number of the monitor in which the largest area of the 
+ * bounding rectangle of @window resides.
  *
- * Returns the number of the monitor in which the largest area of the bounding rectangle
- * of @window resides. 
+ * Since: 2.2
  **/
 gint 
 gdk_screen_get_monitor_at_window (GdkScreen      *screen,
                                  GdkWindow      *window)
 {
-  gint num_monitors, i, sum = 0, screen_num = 0;
+  gint num_monitors, i, area = 0, screen_num = -1;
   GdkRectangle win_rect;
   g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
   
@@ -137,13 +247,18 @@ gdk_screen_get_monitor_at_window (GdkScreen      *screen,
       gdk_screen_get_monitor_geometry (screen, i, &tmp_monitor);
       gdk_rectangle_intersect (&win_rect, &tmp_monitor, &intersect);
       
-      if (intersect.width * intersect.height > sum)
+      if (intersect.width * intersect.height > area)
        { 
-         sum = intersect.width * intersect.height;
+         area = intersect.width * intersect.height;
          screen_num = i;
        }
     }
-  return screen_num;
+  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);
 }
 
 /**
@@ -151,7 +266,7 @@ gdk_screen_get_monitor_at_window (GdkScreen      *screen,
  * 
  * Returns the width of the default screen in pixels.
  * 
- * Return value:  the width of the default screen in pixels.
+ * Return value: the width of the default screen in pixels.
  **/
 gint
 gdk_screen_width (void)
@@ -202,23 +317,5 @@ gdk_screen_height_mm (void)
   return gdk_screen_get_height_mm (gdk_screen_get_default ());
 }
 
-/**
- * gdk_screen_get_window_at_pointer:
- * @screen: a #GdkScreen
- * @win_x: return location for origin of the window under the pointer
- * @win_y: return location for origin of the window under the pointer
- * 
- * Obtains the window underneath the mouse pointer, returning the location
- * of that window in @win_x, @win_y for @screen. Returns %NULL if the window 
- * under the mouse pointer is not known to GDK (for example, belongs to
- * another application).
- * 
- * Returns: the window under the mouse pointer, or %NULL
- **/
-GdkWindow *
-gdk_screen_get_window_at_pointer (GdkScreen *screen,
-                                 gint      *win_x,
-                                 gint      *win_y)
-{
-  return _gdk_current_pointer_hooks->window_at_pointer (screen, win_x, win_y);
-}
+#define __GDK_SCREEN_C__
+#include "gdkaliasdef.c"