mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 14:20:21 +00:00
Add gdk_screen_get_primary_monitor(). This fixes bug #601712
This commit is contained in:
parent
0748cf563d
commit
662e69ad3e
@ -91,6 +91,7 @@ GList * gdk_screen_get_toplevel_windows (GdkScreen *screen);
|
|||||||
gchar * gdk_screen_make_display_name (GdkScreen *screen);
|
gchar * gdk_screen_make_display_name (GdkScreen *screen);
|
||||||
|
|
||||||
gint gdk_screen_get_n_monitors (GdkScreen *screen);
|
gint gdk_screen_get_n_monitors (GdkScreen *screen);
|
||||||
|
gint gdk_screen_get_primary_monitor (GdkScreen *screen);
|
||||||
void gdk_screen_get_monitor_geometry (GdkScreen *screen,
|
void gdk_screen_get_monitor_geometry (GdkScreen *screen,
|
||||||
gint monitor_num,
|
gint monitor_num,
|
||||||
GdkRectangle *dest);
|
GdkRectangle *dest);
|
||||||
|
@ -354,6 +354,31 @@ gdk_screen_get_n_monitors (GdkScreen *screen)
|
|||||||
return GDK_SCREEN_X11 (screen)->n_monitors;
|
return GDK_SCREEN_X11 (screen)->n_monitors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gdk_screen_get_primary_monitor:
|
||||||
|
* @screen: a #GdkScreen.
|
||||||
|
*
|
||||||
|
* Gets the primary monitor for @screen. The primary monitor
|
||||||
|
* is considered the monitor where the 'main desktop' lives.
|
||||||
|
* While normal application windows typically allow the window
|
||||||
|
* manager to place the windows, specialized desktop applications
|
||||||
|
* such as panels should place themselves on the primary monitor.
|
||||||
|
*
|
||||||
|
* If no primary monitor is configured by the user, the return value
|
||||||
|
* will be 0, defaulting to the first monitor.
|
||||||
|
*
|
||||||
|
* Returns: An integer index for the primary monitor, or 0 if none is configured.
|
||||||
|
*
|
||||||
|
* Since: 2.20
|
||||||
|
*/
|
||||||
|
gint
|
||||||
|
gdk_screen_get_primary_monitor (GdkScreen *screen)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
|
||||||
|
|
||||||
|
return GDK_SCREEN_X11 (screen)->primary_monitor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gdk_screen_get_monitor_width_mm:
|
* gdk_screen_get_monitor_width_mm:
|
||||||
* @screen: a #GdkScreen
|
* @screen: a #GdkScreen
|
||||||
@ -722,6 +747,7 @@ init_randr13 (GdkScreen *screen)
|
|||||||
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
|
GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
|
||||||
Display *dpy = GDK_SCREEN_XDISPLAY (screen);
|
Display *dpy = GDK_SCREEN_XDISPLAY (screen);
|
||||||
XRRScreenResources *resources;
|
XRRScreenResources *resources;
|
||||||
|
RROutput primary_output;
|
||||||
int i;
|
int i;
|
||||||
GArray *monitors;
|
GArray *monitors;
|
||||||
gboolean randr12_compat = FALSE;
|
gboolean randr12_compat = FALSE;
|
||||||
@ -733,15 +759,23 @@ init_randr13 (GdkScreen *screen)
|
|||||||
screen_x11->xroot_window);
|
screen_x11->xroot_window);
|
||||||
if (!resources)
|
if (!resources)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
|
monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
|
||||||
resources->noutput);
|
resources->noutput);
|
||||||
|
|
||||||
|
primary_output = XRRGetOutputPrimary (screen_x11->xdisplay,
|
||||||
|
screen_x11->xroot_window);
|
||||||
|
|
||||||
for (i = 0; i < resources->noutput; ++i)
|
for (i = 0; i < resources->noutput; ++i)
|
||||||
{
|
{
|
||||||
XRROutputInfo *output =
|
XRROutputInfo *output =
|
||||||
XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
|
XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
|
||||||
|
|
||||||
|
if (resources->outputs[i] == primary_output)
|
||||||
|
{
|
||||||
|
screen_x11->primary_monitor = i;
|
||||||
|
}
|
||||||
|
|
||||||
/* Non RandR1.2 X driver have output name "default" */
|
/* Non RandR1.2 X driver have output name "default" */
|
||||||
randr12_compat |= !g_strcmp0(output->name, "default");
|
randr12_compat |= !g_strcmp0(output->name, "default");
|
||||||
|
|
||||||
@ -1110,7 +1144,10 @@ _gdk_x11_screen_size_changed (GdkScreen *screen,
|
|||||||
display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
|
display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
|
||||||
|
|
||||||
if (display_x11->have_randr13 && event->type == ConfigureNotify)
|
if (display_x11->have_randr13 && event->type == ConfigureNotify)
|
||||||
return;
|
{
|
||||||
|
g_signal_emit_by_name (screen, "monitors-changed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
XRRUpdateConfiguration (event);
|
XRRUpdateConfiguration (event);
|
||||||
#else
|
#else
|
||||||
|
@ -93,6 +93,7 @@ struct _GdkScreenX11
|
|||||||
/* Xinerama/RandR 1.2 */
|
/* Xinerama/RandR 1.2 */
|
||||||
gint n_monitors;
|
gint n_monitors;
|
||||||
GdkX11Monitor *monitors;
|
GdkX11Monitor *monitors;
|
||||||
|
gint primary_monitor;
|
||||||
|
|
||||||
/* Pango renderer object singleton */
|
/* Pango renderer object singleton */
|
||||||
PangoRenderer *renderer;
|
PangoRenderer *renderer;
|
||||||
|
@ -23,13 +23,15 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
static gint num_monitors;
|
static gint num_monitors;
|
||||||
|
static gint primary_monitor;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
request (GtkWidget *widget,
|
request (GtkWidget *widget,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
gint i = gdk_screen_get_monitor_at_window (gtk_widget_get_screen (widget),
|
GdkScreen *screen = gtk_widget_get_screen (widget);
|
||||||
|
gint i = gdk_screen_get_monitor_at_window (screen,
|
||||||
widget->window);
|
widget->window);
|
||||||
|
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
@ -37,18 +39,35 @@ request (GtkWidget *widget,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
GdkRectangle monitor;
|
GdkRectangle monitor;
|
||||||
gdk_screen_get_monitor_geometry (gtk_widget_get_screen (widget), i, &monitor);
|
|
||||||
|
gdk_screen_get_monitor_geometry (screen,
|
||||||
|
i, &monitor);
|
||||||
|
primary_monitor = gdk_screen_get_primary_monitor (screen);
|
||||||
|
|
||||||
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
|
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
|
||||||
"Monitor %d of %d</span></big>\n"
|
"Monitor %d of %d</span></big>\n"
|
||||||
"<i>Width - Height </i>: (%d,%d)\n"
|
"<i>Width - Height </i>: (%d,%d)\n"
|
||||||
"<i>Top left coordinate </i>: (%d,%d)",i+1, num_monitors,
|
"<i>Top left coordinate </i>: (%d,%d)\n"
|
||||||
monitor.width, monitor.height, monitor.x, monitor.y);
|
"<i>Primary monitor: %d</i>",
|
||||||
|
i + 1, num_monitors,
|
||||||
|
monitor.width, monitor.height,
|
||||||
|
monitor.x, monitor.y,
|
||||||
|
primary_monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_label_set_markup (GTK_LABEL (user_data), str);
|
gtk_label_set_markup (GTK_LABEL (user_data), str);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
monitors_changed_cb (GdkScreen *screen,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GtkWidget *label = (GtkWidget *)data;
|
||||||
|
|
||||||
|
request (label, label);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -63,8 +82,10 @@ main (int argc, char *argv[])
|
|||||||
num_monitors = gdk_screen_get_n_monitors (screen);
|
num_monitors = gdk_screen_get_n_monitors (screen);
|
||||||
if (num_monitors == 1)
|
if (num_monitors == 1)
|
||||||
g_warning ("The default screen of the current display only has one monitor.");
|
g_warning ("The default screen of the current display only has one monitor.");
|
||||||
|
|
||||||
for (i=0; i<num_monitors; i++)
|
primary_monitor = gdk_screen_get_primary_monitor (screen);
|
||||||
|
|
||||||
|
for (i = 0; i < num_monitors; i++)
|
||||||
{
|
{
|
||||||
GdkRectangle monitor;
|
GdkRectangle monitor;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
@ -80,8 +101,12 @@ main (int argc, char *argv[])
|
|||||||
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
|
str = g_strdup_printf ("<big><span foreground='white' background='black'>"
|
||||||
"Monitor %d of %d</span></big>\n"
|
"Monitor %d of %d</span></big>\n"
|
||||||
"<i>Width - Height </i>: (%d,%d)\n"
|
"<i>Width - Height </i>: (%d,%d)\n"
|
||||||
"<i>Top left coordinate </i>: (%d,%d)",i+1, num_monitors,
|
"<i>Top left coordinate </i>: (%d,%d)\n"
|
||||||
monitor.width, monitor.height, monitor.x, monitor.y);
|
"<i>Primary monitor: %d</i>",
|
||||||
|
i + 1, num_monitors,
|
||||||
|
monitor.width, monitor.height,
|
||||||
|
monitor.x, monitor.y,
|
||||||
|
primary_monitor);
|
||||||
gtk_label_set_markup (GTK_LABEL (label), str);
|
gtk_label_set_markup (GTK_LABEL (label), str);
|
||||||
g_free (str);
|
g_free (str);
|
||||||
vbox = gtk_vbox_new (TRUE, 1);
|
vbox = gtk_vbox_new (TRUE, 1);
|
||||||
@ -94,8 +119,11 @@ main (int argc, char *argv[])
|
|||||||
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
|
g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
|
||||||
gtk_container_add (GTK_CONTAINER (vbox), button);
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
|
|
||||||
|
g_signal_connect (screen, "monitors-changed",
|
||||||
|
G_CALLBACK (monitors_changed_cb), label);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user