]> git.saurik.com Git - wxWidgets.git/commitdiff
Use GTK+ functions for wxDisplay implementation.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 22 May 2010 15:48:59 +0000 (15:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 22 May 2010 15:48:59 +0000 (15:48 +0000)
There is no need to use Xinerama for what GDK can do itself (see #11053).

Also don't check for Xinerama in configure when using wxGTK2.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64384 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

configure
configure.in
src/unix/displayx11.cpp

index 4165801b8ad707e6a0c4d562a60b52099c44d766..6a76d2a78ca3a2c3739ceca1c81b2b4b12678744 100755 (executable)
--- a/configure
+++ b/configure
@@ -3606,8 +3606,10 @@ echo "$as_me: error: Please specify at most one toolkit" >&2;}
     # to be removed when --disable-gtk2 isn't needed
     if test "x$wxUSE_GTK2" = "xyes"; then
         wxGTK_VERSION=2
     # to be removed when --disable-gtk2 isn't needed
     if test "x$wxUSE_GTK2" = "xyes"; then
         wxGTK_VERSION=2
+        wxUSE_GTK1=0
     elif test "x$wxUSE_GTK2" = "xno"; then
         wxGTK_VERSION=1
     elif test "x$wxUSE_GTK2" = "xno"; then
         wxGTK_VERSION=1
+        wxUSE_GTK1=1
     fi
 
     for toolkit in $ALL_TOOLKITS; do
     fi
 
     for toolkit in $ALL_TOOLKITS; do
@@ -33538,8 +33540,9 @@ fi
 
 
 
 
 
 
+USE_XINERAMA=0
 if test "$wxUSE_DISPLAY" = "yes"; then
 if test "$wxUSE_DISPLAY" = "yes"; then
-    if test "$wxUSE_UNIX" = "yes" -a "$wxUSE_MAC" != 1 -a "$wxUSE_OLD_COCOA" != 1; then
+        if test "$wxUSE_MOTIF" = 1 -o "$wxUSE_X11" = 1 -o "$wxUSE_GTK1" = 1; then
         { echo "$as_me:$LINENO: checking for Xinerama" >&5
 echo $ECHO_N "checking for Xinerama... $ECHO_C" >&6; }
 
         { echo "$as_me:$LINENO: checking for Xinerama" >&5
 echo $ECHO_N "checking for Xinerama... $ECHO_C" >&6; }
 
@@ -33571,11 +33574,70 @@ echo $ECHO_N "checking for Xinerama... $ECHO_C" >&6; }
             if test "$ac_path_to_link" != " -L/usr/lib" ; then
                 LDFLAGS="$LDFLAGS $ac_path_to_link"
             fi
             if test "$ac_path_to_link" != " -L/usr/lib" ; then
                 LDFLAGS="$LDFLAGS $ac_path_to_link"
             fi
+            USE_XINERAMA=1
             GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXinerama"
             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
             GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXinerama"
             { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
+        else
+            { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+            { echo "$as_me:$LINENO: WARNING: Xinerama not found; disabling wxDisplay" >&5
+echo "$as_me: WARNING: Xinerama not found; disabling wxDisplay" >&2;}
+            wxUSE_DISPLAY="no"
+        fi
+    elif test "$wxUSE_MSW" = 1; then
+                { echo "$as_me:$LINENO: checking for ddraw.h" >&5
+echo $ECHO_N "checking for ddraw.h... $ECHO_C" >&6; }
+if test "${ac_cv_header_ddraw_h+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <windows.h>
+
+#include <ddraw.h>
+_ACEOF
+rm -f conftest.$ac_objext
+if { (ac_try="$ac_compile"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_compile") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+        test -z "$ac_c_werror_flag" ||
+        test ! -s conftest.err
+       } && test -s conftest.$ac_objext; then
+  ac_cv_header_ddraw_h=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
 
-            { echo "$as_me:$LINENO: checking for Xxf86vm extension" >&5
+       ac_cv_header_ddraw_h=no
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_header_ddraw_h" >&5
+echo "${ECHO_T}$ac_cv_header_ddraw_h" >&6; }
+
+
+    fi
+fi
+
+if test "$wxUSE_DISPLAY" = "yes"; then
+        if test "$USE_XINERAMA" = 1 -o "$wxUSE_GTK" = 1; then
+        { echo "$as_me:$LINENO: checking for Xxf86vm extension" >&5
 echo $ECHO_N "checking for Xxf86vm extension... $ECHO_C" >&6; }
 
   ac_find_libraries=
 echo $ECHO_N "checking for Xxf86vm extension... $ECHO_C" >&6; }
 
   ac_find_libraries=
@@ -33589,8 +33651,8 @@ echo $ECHO_N "checking for Xxf86vm extension... $ECHO_C" >&6; }
     done
   done
 
     done
   done
 
-            if test "$ac_find_libraries" != "" ; then
-                { echo "$as_me:$LINENO: result: yes" >&5
+        if test "$ac_find_libraries" != "" ; then
+            { echo "$as_me:$LINENO: result: yes" >&5
 echo "${ECHO_T}yes" >&6; }
 
 for ac_header in X11/extensions/xf86vmode.h
 echo "${ECHO_T}yes" >&6; }
 
 for ac_header in X11/extensions/xf86vmode.h
@@ -33608,9 +33670,9 @@ cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
 
-                                      #if HAVE_X11_XLIB_H
-                                        #include <X11/Xlib.h>
-                                      #endif
+                                  #if HAVE_X11_XLIB_H
+                                    #include <X11/Xlib.h>
+                                  #endif
 
 
 #include <$ac_header>
 
 
 #include <$ac_header>
@@ -33650,71 +33712,16 @@ if test `eval echo '${'$as_ac_Header'}'` = yes; then
 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
 
 #define `echo "HAVE_$ac_header" | $as_tr_cpp` 1
 _ACEOF
 
-                                  GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXxf86vm"
+                              GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXxf86vm"
 
 fi
 
 done
 
 
 fi
 
 done
 
-            else
-                { echo "$as_me:$LINENO: result: no" >&5
-echo "${ECHO_T}no" >&6; }
-            fi
-
         else
             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
         else
             { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
-            { echo "$as_me:$LINENO: WARNING: Xinerama not found; disabling wxDisplay" >&5
-echo "$as_me: WARNING: Xinerama not found; disabling wxDisplay" >&2;}
-            wxUSE_DISPLAY="no"
         fi
         fi
-    elif test "$wxUSE_MSW" = 1; then
-        { echo "$as_me:$LINENO: checking for ddraw.h" >&5
-echo $ECHO_N "checking for ddraw.h... $ECHO_C" >&6; }
-if test "${ac_cv_header_ddraw_h+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  cat >conftest.$ac_ext <<_ACEOF
-/* confdefs.h.  */
-_ACEOF
-cat confdefs.h >>conftest.$ac_ext
-cat >>conftest.$ac_ext <<_ACEOF
-/* end confdefs.h.  */
-#include <windows.h>
-
-#include <ddraw.h>
-_ACEOF
-rm -f conftest.$ac_objext
-if { (ac_try="$ac_compile"
-case "(($ac_try" in
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
-  *) ac_try_echo=$ac_try;;
-esac
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
-  (eval "$ac_compile") 2>conftest.er1
-  ac_status=$?
-  grep -v '^ *+' conftest.er1 >conftest.err
-  rm -f conftest.er1
-  cat conftest.err >&5
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
-  (exit $ac_status); } && {
-        test -z "$ac_c_werror_flag" ||
-        test ! -s conftest.err
-       } && test -s conftest.$ac_objext; then
-  ac_cv_header_ddraw_h=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-       ac_cv_header_ddraw_h=no
-fi
-
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-fi
-{ echo "$as_me:$LINENO: result: $ac_cv_header_ddraw_h" >&5
-echo "${ECHO_T}$ac_cv_header_ddraw_h" >&6; }
-
-
     fi
 fi
 
     fi
 fi
 
index edbde026bbda43139884bf452a5a2eca3e358438..67c0b462c00eb010a3c2289513759308b4456f23 100644 (file)
@@ -563,8 +563,10 @@ if test "$wxUSE_GUI" = "yes"; then
     # to be removed when --disable-gtk2 isn't needed
     if test "x$wxUSE_GTK2" = "xyes"; then
         wxGTK_VERSION=2
     # to be removed when --disable-gtk2 isn't needed
     if test "x$wxUSE_GTK2" = "xyes"; then
         wxGTK_VERSION=2
+        wxUSE_GTK1=0
     elif test "x$wxUSE_GTK2" = "xno"; then
         wxGTK_VERSION=1
     elif test "x$wxUSE_GTK2" = "xno"; then
         wxGTK_VERSION=1
+        wxUSE_GTK1=1
     fi
 
     for toolkit in $ALL_TOOLKITS; do
     fi
 
     for toolkit in $ALL_TOOLKITS; do
@@ -3712,14 +3714,13 @@ fi
 
 
 dnl ---------------------------------------------------------------------------
 
 
 dnl ---------------------------------------------------------------------------
-dnl wxDisplay Sanity checks
+dnl wxDisplay checks
 dnl ---------------------------------------------------------------------------
 
 dnl ---------------------------------------------------------------------------
 
+USE_XINERAMA=0
 if test "$wxUSE_DISPLAY" = "yes"; then
 if test "$wxUSE_DISPLAY" = "yes"; then
-dnl ---------------------------------------------------------------------------
-dnl Xinerama (for unix ) - Brian Victor
-dnl ---------------------------------------------------------------------------
-    if test "$wxUSE_UNIX" = "yes" -a "$wxUSE_MAC" != 1 -a "$wxUSE_OLD_COCOA" != 1; then
+    dnl Xinerama is used for wxGTK1/wxX11/wxMotif only
+    if test "$wxUSE_MOTIF" = 1 -o "$wxUSE_X11" = 1 -o "$wxUSE_GTK1" = 1; then
         AC_MSG_CHECKING([for Xinerama])
         WX_PATH_FIND_LIBRARIES([$SEARCH_LIB],Xinerama)
         if test "$ac_find_libraries" != "" ; then
         AC_MSG_CHECKING([for Xinerama])
         WX_PATH_FIND_LIBRARIES([$SEARCH_LIB],Xinerama)
         if test "$ac_find_libraries" != "" ; then
@@ -3727,40 +3728,43 @@ dnl ---------------------------------------------------------------------------
             if test "$ac_path_to_link" != " -L/usr/lib" ; then
                 LDFLAGS="$LDFLAGS $ac_path_to_link"
             fi
             if test "$ac_path_to_link" != " -L/usr/lib" ; then
                 LDFLAGS="$LDFLAGS $ac_path_to_link"
             fi
+            USE_XINERAMA=1
             GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXinerama"
             AC_MSG_RESULT([yes])
             GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXinerama"
             AC_MSG_RESULT([yes])
-
-            AC_MSG_CHECKING([for Xxf86vm extension])
-            WX_PATH_FIND_LIBRARIES([$SEARCH_LIB],Xxf86vm)
-            if test "$ac_find_libraries" != "" ; then
-                AC_MSG_RESULT([yes])
-                AC_CHECK_HEADERS([X11/extensions/xf86vmode.h],
-                                 [
-                                  GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXxf86vm"
-                                 ],
-                                 [],
-                                 [
-                                      #if HAVE_X11_XLIB_H
-                                        #include <X11/Xlib.h>
-                                      #endif
-                                 ])
-            else
-                AC_MSG_RESULT([no])
-            fi
-
         else
             AC_MSG_RESULT([no])
             AC_MSG_WARN([Xinerama not found; disabling wxDisplay])
             wxUSE_DISPLAY="no"
         fi
     elif test "$wxUSE_MSW" = 1; then
         else
             AC_MSG_RESULT([no])
             AC_MSG_WARN([Xinerama not found; disabling wxDisplay])
             wxUSE_DISPLAY="no"
         fi
     elif test "$wxUSE_MSW" = 1; then
-dnl ---------------------------------------------------------------------------
-dnl DirectDraw for MSW - optionally used by WxDisplay.
-dnl ---------------------------------------------------------------------------
+        dnl DirectDraw for MSW - optionally used by WxDisplay.
         AC_CHECK_HEADER([ddraw.h], [], [], [#include <windows.h>])
     fi
 fi
 
         AC_CHECK_HEADER([ddraw.h], [], [], [#include <windows.h>])
     fi
 fi
 
+if test "$wxUSE_DISPLAY" = "yes"; then
+    dnl wxGTK2 needs Xxf86vm as well as Xinerama-using ports from above
+    if test "$USE_XINERAMA" = 1 -o "$wxUSE_GTK" = 1; then
+        AC_MSG_CHECKING([for Xxf86vm extension])
+        WX_PATH_FIND_LIBRARIES([$SEARCH_LIB],Xxf86vm)
+        if test "$ac_find_libraries" != "" ; then
+            AC_MSG_RESULT([yes])
+            AC_CHECK_HEADERS([X11/extensions/xf86vmode.h],
+                             [
+                              GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXxf86vm"
+                             ],
+                             [],
+                             [
+                                  #if HAVE_X11_XLIB_H
+                                    #include <X11/Xlib.h>
+                                  #endif
+                             ])
+        else
+            AC_MSG_RESULT([no])
+        fi
+    fi
+fi
+
 dnl ---------------------------------------------------------------------------
 dnl X11 session management
 dnl ---------------------------------------------------------------------------
 dnl ---------------------------------------------------------------------------
 dnl X11 session management
 dnl ---------------------------------------------------------------------------
index db0f37b899e1ee09017abd1712c465e612ec51c3..a6c294d5e2b81ea95aa42795bee98bb9f8a4278d 100644 (file)
 
 #include "wx/display_impl.h"
 
 
 #include "wx/display_impl.h"
 
-/* These must be included after the wx files.  Otherwise the Data macro in
- * Xlibint.h conflicts with a function declaration in wx/list.h.  */
-extern "C"
-{
-    #include <X11/Xlib.h>
-    #include <X11/Xlibint.h>
+#ifdef __WXGTK20__
+    #include <gdk/gdk.h>
+    #include <gdk/gdkx.h>
+
+    // define the struct with the same fields as XineramaScreenInfo (except for
+    // screen number which we don't need) but which we can use without
+    // including Xinerama headers
+    struct ScreenInfo
+    {
+       short x_org;
+       short y_org;
+       short width;
+       short height;
+    };
+#else // use raw Xinerama functions
+    /* These must be included after the wx files.  Otherwise the Data macro in
+     * Xlibint.h conflicts with a function declaration in wx/list.h.  */
+    extern "C"
+    {
+        #include <X11/Xlib.h>
+        #include <X11/Xlibint.h>
 
 
-    #include <X11/extensions/Xinerama.h>
-    #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
-        #include <X11/extensions/xf86vmode.h>
-    #endif
-}
+        #include <X11/extensions/Xinerama.h>
+        #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
+            #include <X11/extensions/xf86vmode.h>
+        #endif
+    }
+
+    typedef XineramaScreenInfo ScreenInfo;
+#endif // GTK+/Xinerama
 
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
-// helper class to automatically free XineramaQueryScreens() return value
+// helper class storing information about all screens
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 
-class ScreensInfo
+// the base class provides access to ScreenInfo array, derived class
+// initializes it using either GTK+ or Xinerama functions
+class ScreensInfoBase
+{
+public:
+    operator const ScreenInfo *() const { return m_screens; }
+
+    unsigned GetCount() const { return static_cast<unsigned>(m_num); }
+
+protected:
+    ScreenInfo *m_screens;
+    int m_num;
+};
+
+#ifdef __WXGTK20__
+
+class ScreensInfo : public ScreensInfoBase
 {
 public:
     ScreensInfo()
     {
 {
 public:
     ScreensInfo()
     {
-        m_screens = XineramaQueryScreens((Display *)wxGetDisplay(), &m_num);
+        GdkScreen * const screen = gdk_screen_get_default();
+
+        m_num = gdk_screen_get_n_monitors(screen);
+        m_screens = new ScreenInfo[m_num];
+        for ( int i = 0; i < m_num; i++ )
+        {
+            GdkRectangle rect;
+            gdk_screen_get_monitor_geometry(screen, i, &rect);
+            m_screens[i].x_org = rect.x;
+            m_screens[i].y_org = rect.y;
+            m_screens[i].width = rect.width;
+            m_screens[i].height = rect.height;
+        }
     }
 
     ~ScreensInfo()
     {
     }
 
     ~ScreensInfo()
     {
-        XFree(m_screens);
+        delete [] m_screens;
     }
     }
+};
 
 
-    operator const XineramaScreenInfo *() const { return m_screens; }
+#else // Xinerama
 
 
-    unsigned GetCount() const { return static_cast<unsigned>(m_num); }
+class ScreensInfo : public ScreensInfoBase
+{
+public:
+    ScreensInfo()
+    {
+        m_screens = XineramaQueryScreens((Display *)wxGetDisplay(), &m_num);
+    }
 
 
-private:
-    XineramaScreenInfo *m_screens;
-    int m_num;
+    ~ScreensInfo()
+    {
+        XFree(m_screens);
+    }
 };
 
 };
 
+#endif // GTK+/Xinerama
+
 // ----------------------------------------------------------------------------
 // display and display factory classes
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // display and display factory classes
 // ----------------------------------------------------------------------------
@@ -85,7 +141,7 @@ private:
 class WXDLLEXPORT wxDisplayImplX11 : public wxDisplayImpl
 {
 public:
 class WXDLLEXPORT wxDisplayImplX11 : public wxDisplayImpl
 {
 public:
-    wxDisplayImplX11(unsigned n, const XineramaScreenInfo& info)
+    wxDisplayImplX11(unsigned n, const ScreenInfo& info)
         : wxDisplayImpl(n),
           m_rect(info.x_org, info.y_org, info.width, info.height)
     {
         : wxDisplayImpl(n),
           m_rect(info.x_org, info.y_org, info.width, info.height)
     {
@@ -142,7 +198,7 @@ int wxDisplayFactoryX11::GetFromPoint(const wxPoint& p)
     const unsigned numscreens(screens.GetCount());
     for ( unsigned i = 0; i < numscreens; ++i )
     {
     const unsigned numscreens(screens.GetCount());
     for ( unsigned i = 0; i < numscreens; ++i )
     {
-        const XineramaScreenInfo& s = screens[i];
+        const ScreenInfo& s = screens[i];
         if ( p.x >= s.x_org && p.x < s.x_org + s.width &&
                 p.y >= s.y_org && p.y < s.y_org + s.height )
         {
         if ( p.x >= s.x_org && p.x < s.x_org + s.width &&
                 p.y >= s.y_org && p.y < s.y_org + s.height )
         {
@@ -314,12 +370,13 @@ bool wxDisplayImplX11::ChangeMode(const wxVideoMode& WXUNUSED(mode))
 
 /* static */ wxDisplayFactory *wxDisplay::CreateFactory()
 {
 
 /* static */ wxDisplayFactory *wxDisplay::CreateFactory()
 {
-    if ( XineramaIsActive((Display*)wxGetDisplay()) )
-    {
-        return new wxDisplayFactoryX11;
-    }
+    // GTK+ screen functions are always available, no need to check for them
+#ifndef __WXGTK20__
+    if ( !XineramaIsActive((Display*)wxGetDisplay()) )
+        return new wxDisplayFactorySingle;
+#endif
 
 
-    return new wxDisplayFactorySingle;
+    return new wxDisplayFactoryX11;
 }
 
 #endif /* wxUSE_DISPLAY */
 }
 
 #endif /* wxUSE_DISPLAY */