Commit 026cb538 authored by Руслан Ижбулатов's avatar Руслан Ижбулатов Committed by Matthias Clasen

win32: Port to new monitor api

parent 5c1d0915
......@@ -385,7 +385,7 @@ if test "$enable_win32_backend" = "yes"; then
backend_immodules="$backend_immodules,ime"
GDK_WINDOWING="$GDK_WINDOWING
#define GDK_WINDOWING_WIN32"
GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi"
GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -lgdi32 -limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32"
AM_CONDITIONAL(USE_WIN32, true)
PANGO_PACKAGES="pangowin32 pangocairo"
else
......@@ -756,6 +756,54 @@ case $host in
;;
esac
AS_CASE([$host_os],
[mingw*],
[
AC_CHECK_SIZEOF(
[DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY],
[],
[
#define _WIN32_WINNT 0x601
#include <windows.h>
]
)
AS_IF(
[test x$ac_cv_sizeof_DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY = x4],
[AC_MSG_RESULT([DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY is OK])],
[test x$ac_cv_sizeof_DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY = x0],
[AC_MSG_ERROR([DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY is unavailable])],
[AC_MSG_RESULT([DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY is not OK])]
)
AC_MSG_CHECKING([for SetupDiGetDevicePropertyW])
gtk_save_LIBS="$LIBS"
LIBS="-lsetupapi $LIBS"
AC_TRY_LINK(
[
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <devpropdef.h>
#include <setupapi.h>
],
[return SetupDiGetDevicePropertyW(NULL, NULL, NULL, NULL, NULL, 0, NULL, 0);],
[have_SetupDiGetDevicePropertyW=yes],
[have_SetupDiGetDevicePropertyW=no]
)
AS_IF(
[test x$have_SetupDiGetDevicePropertyW = xyes],
[
AC_DEFINE(
[HAVE_SETUP_DI_GET_DEVICE_PROPERTY_W],
[1],
[Define to 1 if SetupDiGetDevicePropertyW() is available]
)
]
)
AC_MSG_RESULT([$have_SetupDiGetDevicePropertyW])
LIBS="$gtk_save_LIBS"
],
[]
)
AC_SUBST(MATH_LIB)
#
# see bug 162979
......
......@@ -47,6 +47,8 @@ libgdk_win32_la_SOURCES = \
gdkglobals-win32.c \
gdkkeys-win32.c \
gdkmain-win32.c \
gdkmonitor-win32.c \
gdkmonitor-win32.h \
gdkprivate-win32.h \
gdkproperty-win32.c \
gdkscreen-win32.c \
......@@ -56,10 +58,11 @@ libgdk_win32_la_SOURCES = \
gdkwin32display.h \
gdkwin32displaymanager.h \
gdkwin32dnd.h \
gdkwin32glcontext.h \
gdkwin32glcontext.h \
gdkwin32.h \
gdkwin32id.c \
gdkwin32keys.h \
gdkwin32monitor.h \
gdkwin32screen.h \
gdkwin32window.h \
gdkwindow-win32.c \
......@@ -76,9 +79,10 @@ libgdkwin32include_HEADERS = \
gdkwin32display.h \
gdkwin32displaymanager.h\
gdkwin32dnd.h \
gdkwin32glcontext.h \
gdkwin32glcontext.h \
gdkwin32keys.h \
gdkwin32misc.h \
gdkwin32monitor.h \
gdkwin32screen.h \
gdkwin32window.h
......
......@@ -25,10 +25,178 @@
#include "gdkwin32display.h"
#include "gdkwin32screen.h"
#include "gdkwin32window.h"
#include "gdkmonitor-win32.h"
#include "gdkwin32.h"
static int debug_indent = 0;
static GdkMonitor *
_gdk_win32_display_find_matching_monitor (GdkWin32Display *win32_display,
GdkMonitor *needle)
{
int i;
for (i = 0; i < win32_display->monitors->len; i++)
{
GdkWin32Monitor *m;
m = GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i));
if (_gdk_win32_monitor_compare (m, GDK_WIN32_MONITOR (needle)) == 0)
return GDK_MONITOR (m);
}
return NULL;
}
gboolean
_gdk_win32_display_init_monitors (GdkWin32Display *win32_display)
{
GdkDisplay *display = GDK_DISPLAY (win32_display);
GPtrArray *new_monitors;
gint i;
gboolean changed = FALSE;
GdkWin32Monitor *primary_to_move = NULL;
for (i = 0; i < win32_display->monitors->len; i++)
GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i))->remove = TRUE;
new_monitors = _gdk_win32_display_get_monitor_list (win32_display);
for (i = 0; i < new_monitors->len; i++)
{
GdkWin32Monitor *w32_m;
GdkMonitor *m;
GdkWin32Monitor *w32_ex_monitor;
GdkMonitor *ex_monitor;
GdkRectangle geometry, ex_geometry;
GdkRectangle workarea, ex_workarea;
w32_m = GDK_WIN32_MONITOR (g_ptr_array_index (new_monitors, i));
m = GDK_MONITOR (w32_m);
ex_monitor = _gdk_win32_display_find_matching_monitor (win32_display, m);
w32_ex_monitor = GDK_WIN32_MONITOR (ex_monitor);
if (ex_monitor == NULL)
{
w32_m->add = TRUE;
changed = TRUE;
continue;
}
w32_ex_monitor->remove = FALSE;
if (i == 0)
primary_to_move = w32_ex_monitor;
gdk_monitor_get_geometry (m, &geometry);
gdk_monitor_get_geometry (ex_monitor, &ex_geometry);
gdk_monitor_get_workarea (m, &workarea);
gdk_monitor_get_workarea (ex_monitor, &ex_workarea);
if (memcmp (&workarea, &ex_workarea, sizeof (GdkRectangle)) != 0)
{
w32_ex_monitor->work_rect = workarea;
changed = TRUE;
}
if (memcmp (&geometry, &ex_geometry, sizeof (GdkRectangle)) != 0)
{
gdk_monitor_set_size (ex_monitor, geometry.width, geometry.height);
gdk_monitor_set_position (ex_monitor, geometry.x, geometry.y);
changed = TRUE;
}
if (gdk_monitor_get_width_mm (m) != gdk_monitor_get_width_mm (ex_monitor) ||
gdk_monitor_get_height_mm (m) != gdk_monitor_get_height_mm (ex_monitor))
{
gdk_monitor_set_physical_size (ex_monitor,
gdk_monitor_get_width_mm (m),
gdk_monitor_get_height_mm (m));
changed = TRUE;
}
if (g_strcmp0 (gdk_monitor_get_model (m), gdk_monitor_get_model (ex_monitor)) != 0)
{
gdk_monitor_set_model (ex_monitor,
gdk_monitor_get_model (m));
changed = TRUE;
}
if (g_strcmp0 (gdk_monitor_get_manufacturer (m), gdk_monitor_get_manufacturer (ex_monitor)) != 0)
{
gdk_monitor_set_manufacturer (ex_monitor,
gdk_monitor_get_manufacturer (m));
changed = TRUE;
}
if (gdk_monitor_get_refresh_rate (m) != gdk_monitor_get_refresh_rate (ex_monitor))
{
gdk_monitor_set_refresh_rate (ex_monitor, gdk_monitor_get_refresh_rate (m));
changed = TRUE;
}
if (gdk_monitor_get_scale_factor (m) != gdk_monitor_get_scale_factor (ex_monitor))
{
gdk_monitor_set_scale_factor (ex_monitor, gdk_monitor_get_scale_factor (m));
changed = TRUE;
}
if (gdk_monitor_get_subpixel_layout (m) != gdk_monitor_get_subpixel_layout (ex_monitor))
{
gdk_monitor_set_subpixel_layout (ex_monitor, gdk_monitor_get_subpixel_layout (m));
changed = TRUE;
}
}
for (i = win32_display->monitors->len - 1; i >= 0; i--)
{
GdkWin32Monitor *w32_ex_monitor;
GdkMonitor *ex_monitor;
w32_ex_monitor = GDK_WIN32_MONITOR (g_ptr_array_index (win32_display->monitors, i));
ex_monitor = GDK_MONITOR (w32_ex_monitor);
if (!w32_ex_monitor->remove)
continue;
changed = TRUE;
gdk_display_monitor_removed (display, ex_monitor);
g_ptr_array_remove_index (win32_display->monitors, i);
}
for (i = 0; i < new_monitors->len; i++)
{
GdkWin32Monitor *w32_m;
GdkMonitor *m;
w32_m = GDK_WIN32_MONITOR (g_ptr_array_index (new_monitors, i));
m = GDK_MONITOR (w32_m);
if (!w32_m->add)
continue;
gdk_display_monitor_added (display, m);
if (i == 0)
g_ptr_array_insert (win32_display->monitors, 0, g_object_ref (w32_m));
else
g_ptr_array_add (win32_display->monitors, g_object_ref (w32_m));
}
g_ptr_array_free (new_monitors, TRUE);
if (primary_to_move)
{
g_ptr_array_remove (win32_display->monitors, g_object_ref (primary_to_move));
g_ptr_array_insert (win32_display->monitors, 0, primary_to_move);
changed = TRUE;
}
return changed;
}
/**
* gdk_win32_display_set_cursor_theme:
* @display: (type GdkWin32Display): a #GdkDisplay
......@@ -636,12 +804,15 @@ gdk_win32_display_finalize (GObject *object)
_gdk_win32_display_finalize_cursors (display_win32);
_gdk_win32_dnd_exit ();
g_ptr_array_free (display_win32->monitors, TRUE);
G_OBJECT_CLASS (gdk_win32_display_parent_class)->finalize (object);
}
static void
gdk_win32_display_init (GdkWin32Display *display)
{
display->monitors = g_ptr_array_new_with_free_func (g_object_unref);
_gdk_win32_display_init_cursors (display);
}
......@@ -676,6 +847,39 @@ gdk_win32_display_pop_error_trap (GdkDisplay *display,
return 0;
}
static int
gdk_win32_display_get_n_monitors (GdkDisplay *display)
{
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
return win32_display->monitors->len;
}
static GdkMonitor *
gdk_win32_display_get_monitor (GdkDisplay *display,
int monitor_num)
{
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
if (0 <= monitor_num || monitor_num < win32_display->monitors->len)
return (GdkMonitor *) g_ptr_array_index (win32_display->monitors, monitor_num);
return NULL;
}
static GdkMonitor *
gdk_win32_display_get_primary_monitor (GdkDisplay *display)
{
GdkWin32Display *win32_display = GDK_WIN32_DISPLAY (display);
/* We arrange for the first monitor in the array to also be the primiary monitor */
if (win32_display->monitors->len > 0)
return (GdkMonitor *) g_ptr_array_index (win32_display->monitors, 0);
return NULL;
}
static void
gdk_win32_display_class_init (GdkWin32DisplayClass *klass)
{
......@@ -731,5 +935,9 @@ gdk_win32_display_class_init (GdkWin32DisplayClass *klass)
display_class->utf8_to_string_target = _gdk_win32_display_utf8_to_string_target;
display_class->make_gl_context_current = _gdk_win32_display_make_gl_context_current;
display_class->get_n_monitors = gdk_win32_display_get_n_monitors;
display_class->get_monitor = gdk_win32_display_get_monitor;
display_class->get_primary_monitor = gdk_win32_display_get_primary_monitor;
_gdk_win32_windowing_init ();
}
......@@ -42,6 +42,8 @@ struct _GdkWin32Display
HDC gl_hdc;
HWND gl_hwnd;
GPtrArray *monitors;
guint hasWglARBCreateContext : 1;
guint hasWglEXTSwapControl : 1;
guint hasWglOMLSyncControl : 1;
......@@ -52,4 +54,8 @@ struct _GdkWin32DisplayClass
GdkDisplayClass display_class;
};
gboolean _gdk_win32_display_init_monitors (GdkWin32Display *display);
GPtrArray *_gdk_win32_display_get_monitor_list (GdkWin32Display *display);
#endif /* __GDK_DISPLAY__WIN32_H__ */
This diff is collapsed.
/*
* 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_WIN32_MONITOR_PRIVATE_H__
#define __GDK_WIN32_MONITOR_PRIVATE_H__
#include <windows.h>
#include <glib.h>
#include <gio/gio.h>
#include "gdkmonitorprivate.h"
#include "gdkwin32monitor.h"
struct _GdkWin32Monitor
{
GdkMonitor parent;
/* work area */
GdkRectangle work_rect;
/* Device instance path (used to match GdkWin32Monitor to monitor device) */
gchar *instance_path;
/* TRUE if monitor is made up by us
* (this happens when system has logical monitors, but no physical ones).
*/
guint madeup : 1;
/* TRUE if we should notify GDK about this monitor being added */
guint add : 1;
/* TRUE if we should notify GDK about this monitor being removed */
guint remove : 1;
};
struct _GdkWin32MonitorClass {
GdkMonitorClass parent_class;
};
int _gdk_win32_monitor_compare (GdkWin32Monitor *a, GdkWin32Monitor *b);
#endif
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include <gdk/win32/gdkwin32screen.h>
#include <gdk/win32/gdkwin32window.h>
#include <gdk/win32/gdkwin32misc.h>
#include <gdk/win32/gdkwin32monitor.h>
#include <gdk/win32/gdkwin32glcontext.h>
#undef __GDKWIN32_H_INSIDE__
......
/*
* gdkwin32monitor.h
*
* Copyright 2016 Red Hat, Inc.
*
* Matthias Clasen <mclasen@redhat.com>
* Руслан Ижбулатов <lrn1986@gmail.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_WIN32_MONITOR_H__
#define __GDK_WIN32_MONITOR_H__
#if !defined (__GDKWIN32_H_INSIDE__) && !defined (GDK_COMPILATION)
#error "Only <gdk/gdkwin32.h> can be included directly."
#endif
#include <gdk/gdkmonitor.h>
G_BEGIN_DECLS
#define GDK_TYPE_WIN32_MONITOR (gdk_win32_monitor_get_type ())
#define GDK_WIN32_MONITOR(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_WIN32_MONITOR, GdkWin32Monitor))
#define GDK_IS_WIN32_MONITOR(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_WIN32_MONITOR))
#ifdef GDK_COMPILATION
typedef struct _GdkWin32Monitor GdkWin32Monitor;
#else
typedef GdkMonitor GdkWin32Monitor;
#endif
typedef struct _GdkWin32MonitorClass GdkWin32MonitorClass;
GDK_AVAILABLE_IN_3_22
GType gdk_win32_monitor_get_type (void) G_GNUC_CONST;
G_END_DECLS
#endif /* __GDK_WIN32_MONITOR_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment