comparison gtk4/dw.c @ 2324:610c66b17fbc

GTK4: Put Xlib calls in GDK_IS_X11_DISPLAY() code checks. Apparently you can build with multiple backends, so this prevents them being called when not using the X11 backend. Functions will do nothing on non-X11 backends currently.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 17 Feb 2021 07:29:40 +0000
parents 4b04943319c5
children 55524dbe6a54
comparison
equal deleted inserted replaced
2323:4b04943319c5 2324:610c66b17fbc
1706 DW_FUNCTION_ADD_PARAM1(handle) 1706 DW_FUNCTION_ADD_PARAM1(handle)
1707 DW_FUNCTION_RETURN(dw_window_raise, int) 1707 DW_FUNCTION_RETURN(dw_window_raise, int)
1708 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 1708 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
1709 { 1709 {
1710 int retval = DW_ERROR_UNKNOWN; 1710 int retval = DW_ERROR_UNKNOWN;
1711 1711 GdkDisplay *display = gdk_display_get_default();
1712 if(handle && GTK_IS_WINDOW(handle)) 1712
1713 if(handle && GTK_IS_WINDOW(handle) && display && GDK_IS_X11_DISPLAY(display))
1713 { 1714 {
1714 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 1715 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
1715 1716
1716 if(surface) 1717 if(surface)
1717 { 1718 {
1738 DW_FUNCTION_ADD_PARAM1(handle) 1739 DW_FUNCTION_ADD_PARAM1(handle)
1739 DW_FUNCTION_RETURN(dw_window_lower, int) 1740 DW_FUNCTION_RETURN(dw_window_lower, int)
1740 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 1741 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
1741 { 1742 {
1742 int retval = DW_ERROR_UNKNOWN; 1743 int retval = DW_ERROR_UNKNOWN;
1743 1744 GdkDisplay *display = gdk_display_get_default();
1744 if(handle && GTK_IS_WINDOW(handle)) 1745
1746 if(handle && GTK_IS_WINDOW(handle) && display && GDK_IS_X11_DISPLAY(display))
1745 { 1747 {
1746 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 1748 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
1747 1749
1748 if(surface) 1750 if(surface)
1749 { 1751 {
2341 DW_FUNCTION_DEFINITION(dw_window_capture, void, HWND handle) 2343 DW_FUNCTION_DEFINITION(dw_window_capture, void, HWND handle)
2342 DW_FUNCTION_ADD_PARAM1(handle) 2344 DW_FUNCTION_ADD_PARAM1(handle)
2343 DW_FUNCTION_NO_RETURN(dw_window_capture) 2345 DW_FUNCTION_NO_RETURN(dw_window_capture)
2344 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 2346 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
2345 { 2347 {
2346 if(_DWXGrabbedDisplay == NULL && handle && GTK_IS_WINDOW(handle)) 2348 GdkDisplay *display = gdk_display_get_default();
2349
2350 if(_DWXGrabbedDisplay == NULL && handle && GTK_IS_WINDOW(handle) && display && GDK_IS_X11_DISPLAY(display))
2347 { 2351 {
2348 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 2352 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
2349 2353
2350 if(surface) 2354 if(surface)
2351 { 2355 {
2370 #else 2374 #else
2371 DW_FUNCTION_DEFINITION(dw_window_release, void) 2375 DW_FUNCTION_DEFINITION(dw_window_release, void)
2372 DW_FUNCTION_ADD_PARAM 2376 DW_FUNCTION_ADD_PARAM
2373 DW_FUNCTION_NO_RETURN(dw_window_release) 2377 DW_FUNCTION_NO_RETURN(dw_window_release)
2374 { 2378 {
2379 /* Don't need X11 test, _DWXGrabbedDisplay won't get set unless X11 */
2375 if(_DWXGrabbedDisplay) 2380 if(_DWXGrabbedDisplay)
2376 { 2381 {
2377 XUngrabPointer(_DWXGrabbedDisplay, CurrentTime); 2382 XUngrabPointer(_DWXGrabbedDisplay, CurrentTime);
2378 _DWXGrabbedDisplay = NULL; 2383 _DWXGrabbedDisplay = NULL;
2379 } 2384 }
3117 DW_FUNCTION_NO_RETURN(dw_pointer_set_pos) 3122 DW_FUNCTION_NO_RETURN(dw_pointer_set_pos)
3118 DW_FUNCTION_RESTORE_PARAM2(x, long, y, long) 3123 DW_FUNCTION_RESTORE_PARAM2(x, long, y, long)
3119 { 3124 {
3120 GdkDisplay *display = gdk_display_get_default(); 3125 GdkDisplay *display = gdk_display_get_default();
3121 3126
3122 if(display) 3127 if(display && GDK_IS_X11_DISPLAY(display))
3123 { 3128 {
3124 Display *xdisplay = gdk_x11_display_get_xdisplay(display); 3129 Display *xdisplay = gdk_x11_display_get_xdisplay(display);
3125 Window xrootwin = gdk_x11_display_get_xrootwindow(display); 3130 Window xrootwin = gdk_x11_display_get_xrootwindow(display);
3126 3131
3127 if(xdisplay) 3132 if(xdisplay)
8601 DW_FUNCTION_DEFINITION(dw_window_set_pos, void, HWND handle, long x, long y) 8606 DW_FUNCTION_DEFINITION(dw_window_set_pos, void, HWND handle, long x, long y)
8602 DW_FUNCTION_ADD_PARAM3(handle, x, y) 8607 DW_FUNCTION_ADD_PARAM3(handle, x, y)
8603 DW_FUNCTION_NO_RETURN(dw_window_set_pos) 8608 DW_FUNCTION_NO_RETURN(dw_window_set_pos)
8604 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, x, long, y, long) 8609 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, x, long, y, long)
8605 { 8610 {
8606 if(handle && GTK_IS_WINDOW(handle)) 8611 GdkDisplay *display = gdk_display_get_default();
8612
8613 if(handle && GTK_IS_WINDOW(handle) && display && GDK_IS_X11_DISPLAY(display))
8607 { 8614 {
8608 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 8615 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
8609 8616
8610 if(surface) 8617 if(surface)
8611 { 8618 {
8668 } 8675 }
8669 8676
8670 #ifdef GDK_WINDOWING_X11 8677 #ifdef GDK_WINDOWING_X11
8671 { 8678 {
8672 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle)); 8679 GdkSurface *surface = gtk_native_get_surface(GTK_NATIVE(handle));
8673 8680 GdkDisplay *display = gdk_display_get_default();
8674 if(surface) 8681
8682 if(surface && display && GDK_IS_X11_DISPLAY(display))
8675 { 8683 {
8676 GdkDisplay *display = gdk_display_get_default();
8677 XWindowAttributes xwa; 8684 XWindowAttributes xwa;
8678 int ix = 0, iy = 0; 8685 int ix = 0, iy = 0;
8679 8686 Window child, xrootwin = gdk_x11_display_get_xrootwindow(display);
8680 if(display) 8687
8681 { 8688 XTranslateCoordinates(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface),
8682 Window child, xrootwin = gdk_x11_display_get_xrootwindow(display); 8689 xrootwin, 0, 0, &ix, &iy, &child);
8683
8684 XTranslateCoordinates(GDK_SURFACE_XDISPLAY(surface), GDK_SURFACE_XID(surface),
8685 xrootwin, 0, 0, &ix, &iy, &child);
8686
8687 }
8688
8689 XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface), 8690 XGetWindowAttributes(GDK_SURFACE_XDISPLAY(surface),
8690 GDK_SURFACE_XID(surface), &xwa); 8691 GDK_SURFACE_XID(surface), &xwa);
8692
8691 if(x) 8693 if(x)
8692 *x = (long)(ix - xwa.x); 8694 *x = (long)(ix - xwa.x);
8693 if(y) 8695 if(y)
8694 *y = (long)(ix - xwa.y); 8696 *y = (long)(ix - xwa.y);
8695 } 8697 }