make GtkWindow track the monitor number
This commit is contained in:
committed by
Davyd Madeley
parent
c43a02ba55
commit
85641efa08
@@ -5493,6 +5493,7 @@ gtk_widget_set_has_tooltip
|
||||
gtk_widget_trigger_tooltip_query
|
||||
gtk_widget_get_snapshot
|
||||
gtk_widget_get_window
|
||||
gtk_widget_get_monitor_num
|
||||
<SUBSECTION>
|
||||
gtk_requisition_copy
|
||||
gtk_requisition_free
|
||||
@@ -5614,6 +5615,7 @@ gtk_window_set_icon_name
|
||||
gtk_window_set_auto_startup_notification
|
||||
gtk_window_get_opacity
|
||||
gtk_window_set_opacity
|
||||
gtk_window_get_monitor_num
|
||||
<SUBSECTION Standard>
|
||||
GTK_WINDOW
|
||||
GTK_IS_WINDOW
|
||||
|
||||
@@ -5018,6 +5018,7 @@ gtk_widget_unmap
|
||||
gtk_widget_unparent
|
||||
gtk_widget_unrealize
|
||||
gtk_widget_get_window
|
||||
gtk_widget_get_monitor_num
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -5142,6 +5143,7 @@ gtk_window_stick
|
||||
gtk_window_unfullscreen
|
||||
gtk_window_unmaximize
|
||||
gtk_window_unstick
|
||||
gtk_window_get_monitor_num
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -10337,5 +10337,38 @@ gtk_widget_get_window (GtkWidget *widget)
|
||||
return widget->window;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_get_monitor_num:
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Gets the monitor number for the widget. Returns -1 if the widget is
|
||||
* not part of a top-level.
|
||||
*
|
||||
* Returns: the monitor number
|
||||
*
|
||||
* Since: 2.14
|
||||
**/
|
||||
gint
|
||||
gtk_widget_get_monitor_num (GtkWidget *widget)
|
||||
{
|
||||
int monitor_num;
|
||||
GtkWidget *toplevel;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), -1);
|
||||
|
||||
monitor_num = -1;
|
||||
|
||||
toplevel = gtk_widget_get_toplevel (widget);
|
||||
if (toplevel != NULL)
|
||||
{
|
||||
if (GTK_WIDGET_TOPLEVEL (toplevel) && GTK_IS_WINDOW (toplevel))
|
||||
{
|
||||
monitor_num = gtk_window_get_monitor_num (GTK_WINDOW (toplevel));
|
||||
}
|
||||
}
|
||||
|
||||
return monitor_num;
|
||||
}
|
||||
|
||||
#define __GTK_WIDGET_C__
|
||||
#include "gtkaliasdef.c"
|
||||
|
||||
@@ -743,6 +743,8 @@ void gtk_widget_style_get (GtkWidget *widget,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
|
||||
gint gtk_widget_get_monitor_num (GtkWidget *widget);
|
||||
|
||||
/* Set certain default values to be used at widget creation time.
|
||||
*/
|
||||
void gtk_widget_set_default_colormap (GdkColormap *colormap);
|
||||
|
||||
@@ -97,6 +97,7 @@ enum {
|
||||
/* Readonly properties */
|
||||
PROP_IS_ACTIVE,
|
||||
PROP_HAS_TOPLEVEL_FOCUS,
|
||||
PROP_MONITOR_NUM,
|
||||
|
||||
/* Writeonly properties */
|
||||
PROP_STARTUP_ID,
|
||||
@@ -190,6 +191,8 @@ struct _GtkWindowPrivate
|
||||
gdouble opacity;
|
||||
|
||||
gchar *startup_id;
|
||||
|
||||
gint monitor_num;
|
||||
};
|
||||
|
||||
static void gtk_window_dispose (GObject *object);
|
||||
@@ -297,6 +300,8 @@ static GtkKeyHash *gtk_window_get_key_hash (GtkWindow *window);
|
||||
static void gtk_window_free_key_hash (GtkWindow *window);
|
||||
static void gtk_window_on_composited_changed (GdkScreen *screen,
|
||||
GtkWindow *window);
|
||||
static void gtk_window_update_monitor_num (GtkWindow *window);
|
||||
|
||||
|
||||
static GSList *toplevel_list = NULL;
|
||||
static guint window_signals[LAST_SIGNAL] = { 0 };
|
||||
@@ -778,6 +783,24 @@ gtk_window_class_init (GtkWindowClass *klass)
|
||||
1.0,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkWindow:monitor-num:
|
||||
*
|
||||
* The monitor number for which the largest area of the window
|
||||
* resides. -1 if window is not realized.
|
||||
*
|
||||
* Since: 2.14
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_MONITOR_NUM,
|
||||
g_param_spec_int ("monitor-num",
|
||||
P_("Monitor Number"),
|
||||
P_("The monitor number for which the largest area of the window resides"),
|
||||
-1,
|
||||
G_MAXINT,
|
||||
-1,
|
||||
GTK_PARAM_READABLE));
|
||||
|
||||
window_signals[SET_FOCUS] =
|
||||
g_signal_new (I_("set-focus"),
|
||||
G_TYPE_FROM_CLASS (gobject_class),
|
||||
@@ -929,6 +952,7 @@ gtk_window_init (GtkWindow *window)
|
||||
priv->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
|
||||
priv->opacity = 1.0;
|
||||
priv->startup_id = NULL;
|
||||
priv->monitor_num = -1;
|
||||
|
||||
colormap = _gtk_widget_peek_colormap ();
|
||||
if (colormap)
|
||||
@@ -1165,6 +1189,9 @@ gtk_window_get_property (GObject *object,
|
||||
case PROP_OPACITY:
|
||||
g_value_set_double (value, gtk_window_get_opacity (window));
|
||||
break;
|
||||
case PROP_MONITOR_NUM:
|
||||
g_value_set_int (value, priv->monitor_num);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -4666,6 +4693,7 @@ gtk_window_unmap (GtkWidget *widget)
|
||||
window->stick_initially = (state & GDK_WINDOW_STATE_STICKY) != 0;
|
||||
priv->above_initially = (state & GDK_WINDOW_STATE_ABOVE) != 0;
|
||||
priv->below_initially = (state & GDK_WINDOW_STATE_BELOW) != 0;
|
||||
priv->monitor_num = -1;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -5006,6 +5034,29 @@ gtk_window_frame_event (GtkWindow *window, GdkEvent *event)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_window_update_monitor_num (GtkWindow *window)
|
||||
{
|
||||
GdkWindow *gdk_window;
|
||||
GtkWindowPrivate *priv = GTK_WINDOW_GET_PRIVATE (window);
|
||||
gint prev_monitor_num;
|
||||
|
||||
prev_monitor_num = priv->monitor_num;
|
||||
|
||||
gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
|
||||
if (gdk_window == NULL)
|
||||
priv->monitor_num = -1;
|
||||
else
|
||||
priv->monitor_num = gdk_screen_get_monitor_at_window (window->screen, gdk_window);
|
||||
|
||||
if (priv->monitor_num != prev_monitor_num &&
|
||||
priv->monitor_num != -1)
|
||||
{
|
||||
/*g_debug ("monitor num changed from %d to %d for top-level %p (screen %p)", prev_monitor_num, priv->monitor_num, window, window->screen);*/
|
||||
g_object_notify (G_OBJECT (window), "monitor-num");
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
gtk_window_configure_event (GtkWidget *widget,
|
||||
GdkEventConfigure *event)
|
||||
@@ -5030,6 +5081,8 @@ gtk_window_configure_event (GtkWidget *widget,
|
||||
window->configure_request_count -= 1;
|
||||
gdk_window_thaw_toplevel_updates_libgtk_only (widget->window);
|
||||
}
|
||||
|
||||
gtk_window_update_monitor_num (window);
|
||||
|
||||
/* As an optimization, we avoid a resize when possible.
|
||||
*
|
||||
@@ -8443,5 +8496,28 @@ gtk_window_set_default_icon_from_file (const gchar *filename,
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* gtk_window_get_monitor_num:
|
||||
* @window: a #GtkWindow
|
||||
*
|
||||
* Gets the monitor number for which the largest area of the window
|
||||
* resides. If the window is not realized, -1 is returned.
|
||||
*
|
||||
* Returns: the monitor number
|
||||
*
|
||||
* Since: 2.14
|
||||
**/
|
||||
gint
|
||||
gtk_window_get_monitor_num (GtkWindow *window)
|
||||
{
|
||||
GtkWindowPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WINDOW (window), -1);
|
||||
|
||||
priv = GTK_WINDOW_GET_PRIVATE (window);
|
||||
|
||||
return priv->monitor_num;
|
||||
}
|
||||
|
||||
#define __GTK_WINDOW_C__
|
||||
#include "gtkaliasdef.c"
|
||||
|
||||
@@ -382,6 +382,8 @@ gboolean gtk_window_parse_geometry (GtkWindow *window,
|
||||
const gchar *geometry);
|
||||
GtkWindowGroup *gtk_window_get_group (GtkWindow *window);
|
||||
|
||||
gint gtk_window_get_monitor_num (GtkWindow *window);
|
||||
|
||||
/* Ignore this unless you are writing a GUI builder */
|
||||
void gtk_window_reshow_with_initial_size (GtkWindow *window);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user