x11: Port to new monitor api
This commit is contained in:
		@ -43,6 +43,8 @@ libgdk_x11_la_SOURCES = 	\
 | 
			
		||||
	gdkglcontext-x11.h	\
 | 
			
		||||
	gdkkeys-x11.c		\
 | 
			
		||||
	gdkmain-x11.c		\
 | 
			
		||||
	gdkmonitor-x11.c	\
 | 
			
		||||
	gdkmonitor-x11.h	\
 | 
			
		||||
	gdkproperty-x11.c	\
 | 
			
		||||
	gdkscreen-x11.c		\
 | 
			
		||||
	gdkscreen-x11.h		\
 | 
			
		||||
@ -76,6 +78,7 @@ libgdkx11include_HEADERS = 	\
 | 
			
		||||
	gdkx11dnd.h		\
 | 
			
		||||
	gdkx11glcontext.h	\
 | 
			
		||||
	gdkx11keys.h		\
 | 
			
		||||
	gdkx11monitor.h		\
 | 
			
		||||
	gdkx11property.h	\
 | 
			
		||||
	gdkx11screen.h		\
 | 
			
		||||
	gdkx11selection.h	\
 | 
			
		||||
 | 
			
		||||
@ -180,6 +180,7 @@ G_DEFINE_TYPE_WITH_CODE (GdkX11Display, gdk_x11_display, GDK_TYPE_DISPLAY,
 | 
			
		||||
static void
 | 
			
		||||
gdk_x11_display_init (GdkX11Display *display)
 | 
			
		||||
{
 | 
			
		||||
  display->monitors = g_ptr_array_new_with_free_func (g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
@ -1903,6 +1904,8 @@ gdk_x11_display_finalize (GObject *object)
 | 
			
		||||
  g_object_unref (display_x11->screen);
 | 
			
		||||
  g_list_free_full (display_x11->screens, g_object_unref);
 | 
			
		||||
 | 
			
		||||
  g_ptr_array_free (display_x11->monitors, TRUE);
 | 
			
		||||
 | 
			
		||||
  g_free (display_x11->startup_notification_id);
 | 
			
		||||
 | 
			
		||||
  /* X ID hashtable */
 | 
			
		||||
@ -2903,6 +2906,38 @@ gdk_x11_display_get_default_seat (GdkDisplay *display)
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
gdk_x11_display_get_n_monitors (GdkDisplay *display)
 | 
			
		||||
{
 | 
			
		||||
  GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
 | 
			
		||||
 | 
			
		||||
  return x11_display->monitors->len;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static GdkMonitor *
 | 
			
		||||
gdk_x11_display_get_monitor (GdkDisplay *display,
 | 
			
		||||
                             int         monitor_num)
 | 
			
		||||
{
 | 
			
		||||
  GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
 | 
			
		||||
 | 
			
		||||
  if (0 <= monitor_num || monitor_num < x11_display->monitors->len)
 | 
			
		||||
    return (GdkMonitor *)x11_display->monitors->pdata[monitor_num];
 | 
			
		||||
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static GdkMonitor *
 | 
			
		||||
gdk_x11_display_get_primary_monitor (GdkDisplay *display)
 | 
			
		||||
{
 | 
			
		||||
  GdkX11Display *x11_display = GDK_X11_DISPLAY (display);
 | 
			
		||||
 | 
			
		||||
  if (0 <= x11_display->primary_monitor && x11_display->primary_monitor < x11_display->monitors->len)
 | 
			
		||||
    return x11_display->monitors->pdata[x11_display->primary_monitor];
 | 
			
		||||
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gdk_x11_display_class_init (GdkX11DisplayClass * class)
 | 
			
		||||
{
 | 
			
		||||
@ -2959,5 +2994,9 @@ gdk_x11_display_class_init (GdkX11DisplayClass * class)
 | 
			
		||||
 | 
			
		||||
  display_class->get_default_seat = gdk_x11_display_get_default_seat;
 | 
			
		||||
 | 
			
		||||
  display_class->get_n_monitors = gdk_x11_display_get_n_monitors;
 | 
			
		||||
  display_class->get_monitor = gdk_x11_display_get_monitor;
 | 
			
		||||
  display_class->get_primary_monitor = gdk_x11_display_get_primary_monitor;
 | 
			
		||||
 | 
			
		||||
  _gdk_x11_windowing_init ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -100,6 +100,9 @@ struct _GdkX11Display
 | 
			
		||||
  /* input GdkWindow list */
 | 
			
		||||
  GList *input_windows;
 | 
			
		||||
 | 
			
		||||
  GPtrArray *monitors;
 | 
			
		||||
  int primary_monitor;
 | 
			
		||||
 | 
			
		||||
  /* Startup notification */
 | 
			
		||||
  gchar *startup_notification_id;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										102
									
								
								gdk/x11/gdkmonitor-x11.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								gdk/x11/gdkmonitor-x11.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,102 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright © 2016 Red Hat, Inc
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Library General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Library General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Library General Public
 | 
			
		||||
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
#include <glib.h>
 | 
			
		||||
#include <gio/gio.h>
 | 
			
		||||
 | 
			
		||||
#include "gdkmonitor-x11.h"
 | 
			
		||||
#include "gdkscreen-x11.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (GdkX11Monitor, gdk_x11_monitor, GDK_TYPE_MONITOR)
 | 
			
		||||
 | 
			
		||||
static gboolean
 | 
			
		||||
gdk_monitor_has_fullscreen_window (GdkMonitor *monitor)
 | 
			
		||||
{
 | 
			
		||||
  GdkScreen *screen = gdk_display_get_default_screen (monitor->display);
 | 
			
		||||
  GList *toplevels, *l;
 | 
			
		||||
  GdkWindow *window;
 | 
			
		||||
  gboolean has_fullscreen;
 | 
			
		||||
 | 
			
		||||
  toplevels = gdk_screen_get_toplevel_windows (screen);
 | 
			
		||||
 | 
			
		||||
  has_fullscreen = FALSE;
 | 
			
		||||
  for (l = toplevels; l; l = l->next)
 | 
			
		||||
    {
 | 
			
		||||
      window = l->data;
 | 
			
		||||
 | 
			
		||||
      if ((gdk_window_get_state (window) & GDK_WINDOW_STATE_FULLSCREEN) == 0)
 | 
			
		||||
        continue;
 | 
			
		||||
 | 
			
		||||
      if (gdk_window_get_fullscreen_mode (window) == GDK_FULLSCREEN_ON_ALL_MONITORS ||
 | 
			
		||||
          gdk_display_get_monitor_at_window (monitor->display, window) == monitor)
 | 
			
		||||
        {
 | 
			
		||||
          has_fullscreen = TRUE;
 | 
			
		||||
          break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  g_list_free (toplevels);
 | 
			
		||||
 | 
			
		||||
  return has_fullscreen;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gdk_x11_monitor_get_workarea (GdkMonitor   *monitor,
 | 
			
		||||
                              GdkRectangle *dest)
 | 
			
		||||
{
 | 
			
		||||
  GdkScreen *screen = gdk_display_get_default_screen (monitor->display);
 | 
			
		||||
  GdkRectangle workarea;
 | 
			
		||||
 | 
			
		||||
  gdk_monitor_get_geometry (monitor, dest);
 | 
			
		||||
 | 
			
		||||
  /* The EWMH constrains workarea to be a rectangle, so it
 | 
			
		||||
   * can't adequately deal with L-shaped monitor arrangements.
 | 
			
		||||
   * As a workaround, we ignore the workarea for anything
 | 
			
		||||
   * but the primary monitor. Since that is where the 'desktop
 | 
			
		||||
   * chrome' usually lives, this works ok in practice.
 | 
			
		||||
   */
 | 
			
		||||
  if (gdk_monitor_is_primary (monitor) &&
 | 
			
		||||
      !gdk_monitor_has_fullscreen_window (monitor))
 | 
			
		||||
    {
 | 
			
		||||
      gdk_x11_screen_get_work_area (screen, &workarea);
 | 
			
		||||
      if (gdk_rectangle_intersect (dest, &workarea, &workarea))
 | 
			
		||||
        *dest = workarea;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gdk_x11_monitor_init (GdkX11Monitor *monitor)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
gdk_x11_monitor_class_init (GdkX11MonitorClass *class)
 | 
			
		||||
{
 | 
			
		||||
  GDK_MONITOR_CLASS (class)->get_workarea = gdk_x11_monitor_get_workarea;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
XID
 | 
			
		||||
gdk_x11_monitor_get_output (GdkMonitor *monitor)
 | 
			
		||||
{
 | 
			
		||||
  g_return_val_if_fail (GDK_IS_X11_MONITOR (monitor), 0);
 | 
			
		||||
 | 
			
		||||
  return GDK_X11_MONITOR (monitor)->output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										43
									
								
								gdk/x11/gdkmonitor-x11.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								gdk/x11/gdkmonitor-x11.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,43 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright © 2016 Red Hat, Inc
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Library General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Library General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Library General Public
 | 
			
		||||
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __GDK_X11_MONITOR_PRIVATE_H__
 | 
			
		||||
#define __GDK_X11_MONITOR_PRIVATE_H__
 | 
			
		||||
 | 
			
		||||
#include <glib.h>
 | 
			
		||||
#include <gio/gio.h>
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
 | 
			
		||||
#include "gdkmonitorprivate.h"
 | 
			
		||||
 | 
			
		||||
#include "gdkx11monitor.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct _GdkX11Monitor
 | 
			
		||||
{
 | 
			
		||||
  GdkMonitor parent;
 | 
			
		||||
 | 
			
		||||
  XID output;
 | 
			
		||||
  guint add     : 1;
 | 
			
		||||
  guint remove  : 1;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _GdkX11MonitorClass {
 | 
			
		||||
  GdkMonitorClass parent_class;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -42,10 +42,6 @@ struct _GdkX11Screen
 | 
			
		||||
  Window xroot_window;
 | 
			
		||||
  GdkWindow *root_window;
 | 
			
		||||
  gint screen_num;
 | 
			
		||||
  /* Xinerama/RandR 1.2 */
 | 
			
		||||
  gint  n_monitors;
 | 
			
		||||
  GdkX11Monitor *monitors;
 | 
			
		||||
  gint primary_monitor;
 | 
			
		||||
 | 
			
		||||
  gint width;
 | 
			
		||||
  gint height;
 | 
			
		||||
@ -116,8 +112,6 @@ void _gdk_x11_screen_size_changed           (GdkScreen *screen,
 | 
			
		||||
					     XEvent    *event);
 | 
			
		||||
void _gdk_x11_screen_process_owner_change   (GdkScreen *screen,
 | 
			
		||||
					     XEvent    *event);
 | 
			
		||||
gint _gdk_x11_screen_get_xinerama_index     (GdkScreen *screen,
 | 
			
		||||
					     gint       monitor_num);
 | 
			
		||||
void _gdk_x11_screen_get_edge_monitors      (GdkScreen *screen,
 | 
			
		||||
					     gint      *top,
 | 
			
		||||
					     gint      *bottom,
 | 
			
		||||
@ -125,6 +119,8 @@ void _gdk_x11_screen_get_edge_monitors      (GdkScreen *screen,
 | 
			
		||||
					     gint      *right);
 | 
			
		||||
void _gdk_x11_screen_set_window_scale       (GdkX11Screen *x11_screen,
 | 
			
		||||
					     int        scale);
 | 
			
		||||
void gdk_x11_screen_get_work_area           (GdkScreen    *screen,
 | 
			
		||||
                                             GdkRectangle *area);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -4215,8 +4215,9 @@ gdk_x11_window_apply_fullscreen_mode (GdkWindow *window)
 | 
			
		||||
	  /* Translate all 4 monitors from the GDK set into XINERAMA indices */
 | 
			
		||||
	  for (i = 0; i < 4; ++i)
 | 
			
		||||
	    {
 | 
			
		||||
	      xclient.data.l[i] = _gdk_x11_screen_get_xinerama_index (GDK_WINDOW_SCREEN (window),
 | 
			
		||||
								      gdk_monitors[i]);
 | 
			
		||||
              /* FIXME
 | 
			
		||||
               xclient.data.l[i] = _gdk_x11_screen_ge_xinerama_index (GDK_WINDOW_SCREEN (window), gdk_monitors[i]); */
 | 
			
		||||
	      xclient.data.l[i] = 0;
 | 
			
		||||
	      /* Sanity check, if XINERAMA is not available, we could have invalid
 | 
			
		||||
	       * negative values for the XINERAMA indices.
 | 
			
		||||
	       */
 | 
			
		||||
 | 
			
		||||
@ -45,6 +45,7 @@
 | 
			
		||||
#include <gdk/x11/gdkx11dnd.h>
 | 
			
		||||
#include <gdk/x11/gdkx11glcontext.h>
 | 
			
		||||
#include <gdk/x11/gdkx11keys.h>
 | 
			
		||||
#include <gdk/x11/gdkx11monitor.h>
 | 
			
		||||
#include <gdk/x11/gdkx11property.h>
 | 
			
		||||
#include <gdk/x11/gdkx11screen.h>
 | 
			
		||||
#include <gdk/x11/gdkx11selection.h>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										48
									
								
								gdk/x11/gdkx11monitor.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								gdk/x11/gdkx11monitor.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,48 @@
 | 
			
		||||
/*
 | 
			
		||||
 * gdkx11monitor.h
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright 2016 Red Hat, Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * Matthias Clasen <mclasen@redhat.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Library General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Library General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Library General Public
 | 
			
		||||
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __GDK_X11_MONITOR_H__
 | 
			
		||||
#define __GDK_X11_MONITOR_H__
 | 
			
		||||
 | 
			
		||||
#if !defined (__GDKX_H_INSIDE__) && !defined (GDK_COMPILATION)
 | 
			
		||||
#error "Only <gdk/gdkx.h> can be included directly."
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <gdk/gdkmonitor.h>
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
#define GDK_TYPE_X11_MONITOR           (gdk_x11_monitor_get_type ())
 | 
			
		||||
#define GDK_X11_MONITOR(object)        (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_X11_MONITOR, GdkX11Monitor))
 | 
			
		||||
#define GDK_IS_X11_MONITOR(object)     (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_X11_MONITOR))
 | 
			
		||||
 | 
			
		||||
typedef struct _GdkX11Monitor      GdkX11Monitor;
 | 
			
		||||
typedef struct _GdkX11MonitorClass GdkX11MonitorClass;
 | 
			
		||||
 | 
			
		||||
GDK_AVAILABLE_IN_3_22
 | 
			
		||||
GType             gdk_x11_monitor_get_type            (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
GDK_AVAILABLE_IN_3_22
 | 
			
		||||
XID               gdk_x11_monitor_get_output          (GdkMonitor *monitor);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
 | 
			
		||||
#endif  /* __GDK_X11_MONITOR_H__ */
 | 
			
		||||
		Reference in New Issue
	
	Block a user